package com.onpositive.datacollection.proxy;

import com.onpositive.data.IPropertyConstants;
import com.onpositive.data.IPropertyMetadata;
import com.onpositive.data.kvstorage.KeyValueBasedCollection;
import com.onpositive.data.kvstorage.KeyValueDataCollection;
import com.onpositive.datamap.item.SingleDataObject;

public abstract class KeyValueBasedCollectionProxy implements IRemoteCollectionProxy{

	
	
	@Override
	public RemoteCollectionInfo getDetailedInfo(String collectionId) {
		KeyValueDataCollection cm=getCollection(collectionId);
		IPropertyMetadata[] meta = cm.getMeta();
		RemoteCollectionInfo m=new RemoteCollectionInfo(meta,cm.getCount());
		byte[]ds=((KeyValueBasedCollection)cm.getCollection()).getReaderData(IPropertyConstants.DOCUMENT_NAME_PROPERTY_METADATA_ID);
		m.nameReader=ds;
		return m;
	}

	@Override
	public byte[] getPropertyData(String collectionId, String propId) {
		KeyValueDataCollection m=getCollection(collectionId);
		return ((KeyValueBasedCollection)m.getCollection()).getReaderData(propId);
	}

	@Override
	public SingleDataObject getObject(String collectionId, String id) {
		KeyValueDataCollection m=getCollection(collectionId);
		return m.getSingleDataObject(id);
	}

	protected abstract KeyValueDataCollection getCollection(String collectionId) ;

}
